// pages/equipmentMap/equipmentMap.js
let mockData = [
  "{\"WorkBodyId\":\"60cc597d6e5341507d49bb5d\",\"Name\":\"东区刘连华\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"东区人员\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"刘连华\",\"Phone\":\"13869670930\",\"Latitude\":\"36.88296829686465\",\"Longitude\":\"118.7401055345469\",\"RelatedFunction\":\"1\"}",
  "{\"WorkBodyId\":\"60cc597b6e5341507d49bb59\",\"Name\":\"东区稻田李月玲\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"稻田一体化\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"李月玲\",\"Phone\":\"15169688320\",\"Latitude\":\"36.842203668460634\",\"Longitude\":\"118.91514204780492\",\"RelatedFunction\":\"1\"}",
  "{\"WorkBodyId\":\"60cc597a6e5341507d49bb55\",\"Name\":\"东片上口李树宣\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"上口一体化\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"李树宣\",\"Phone\":\"15153659565\",\"Latitude\":\"36.962249818928186\",\"Longitude\":\"118.89944331869128\",\"RelatedFunction\":\"1\"}",
  "{\"WorkBodyId\":\"60cc59786e5341507d49bb52\",\"Name\":\"督查张清淑\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"督查部人员\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"张清淑\",\"Phone\":\"15966084220\",\"Latitude\":\"36.88285798058772\",\"Longitude\":\"118.73971621688361\",\"RelatedFunction\":\"1\"}",
  "{\"WorkBodyId\":\"60cc59766e5341507d49bb4e\",\"Name\":\"临朐城关李建军\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"临朐城关街道\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"李建军\",\"Phone\":\"\",\"Latitude\":\"36.85541\",\"Longitude\":\"118.79098\",\"RelatedFunction\":\"1\"}",
  "{\"WorkBodyId\":\"60cc59746e5341507d49bb49\",\"Name\":\"东区五队高怀德\",\"WorkBodyType\":\"2\",\"WorkBodyStatus\":\"-1\",\"JobNum\":\"\",\"DepartName\":\"东区五队\",\"CarTypeName\":\"业务负责人\",\"UserPersonName\":\"高怀德\",\"Phone\":\"13685362526\",\"Latitude\":\"36.88250793046594\",\"Longitude\":\"118.74004643700512\",\"RelatedFunction\":\"1\"}"
]
Page({

  /**
   * 页面的初始数据
   */
  data: {
    includePoints: [], markers: [],
    activeKey: null,
    customCalloutList: [
      {label: '设备名称', prop: 'id'},
      {label: '设备描述', prop: 'id'},
      {label: '设备型号', prop: 'id'},
      {label: '备注', prop: 'id'},
      {label: '测试列1', prop: 'id'},
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  mapTab() {
  },
  markertap({detail}) {
    let {Latitude, Longitude} = JSON.parse(mockData[detail.markerId]);
    
    let markers = mockData.map((value, index) => {
      let {Latitude, Longitude} = JSON.parse(value);
      let marker = {
        id: index,
        iconPath: index % 2 ? '../../static/image/markerError.png' : '../../static/image/markerSuccess.png',
        latitude: Latitude,
        longitude: Longitude,
      };
      if(index === detail.markerId) {
        marker.customCallout = {
          display: 'ALWAYS',
        }
      }
      return marker;
    });
    this.setData({
      markers,
      activeKey: detail.markerId,
      includePoints: [
        {
          latitude: Latitude,
          longitude: Longitude
        }
      ]
    });
  },
  onLoad: function (options) {
      // 模拟请求
      wx.showLoading({
        title: '加载中',
      });
      setTimeout(() => {
        wx.hideLoading();
        let includePoints = [];
        let markers = mockData.map((value, index) => {
          let {Latitude, Longitude} = JSON.parse(value);
          includePoints.push({
            latitude: Latitude,
            longitude: Longitude
          })
          return {
            id: index,
            iconPath: index % 2 ? '../../static/image/markerError.png' : '../../static/image/markerSuccess.png',
            latitude: Latitude,
            longitude: Longitude,
          }
        });
        this.setData({
          markers, includePoints
        })
      }, 1000)
  },
  goInfo() {
    console.log(1)
    wx.navigateTo({
      url: '../equipmentInfo/equipmentInfo',
    })
  },
})